<script setup lang="ts">
import { getWorkerHours } from './'
import type {
  CustomDialogInstance,
  TableColumn,
} from '@/types'
// ------------------use------------------
// #region
defineProps<{
  unitShiftData: any[]
}>()
// #endregion
// ------------------静态变量------------------
// #region
const columns: TableColumn<any>[] = [
  {
    key: uuid(),
    label: '班次名称',
    prop: 'name',
  },
  {
    key: uuid(),
    label: '排班时间',
    width: '120px',
    render({ row }) {
      return `${row.startTime} - ${row.endTime}`
    },
  },
  {
    key: uuid(),
    label: '是否跨天',
    render({ row }) {
      return row.overnightShift ? '是' : '否'
    },
  },
  {
    key: uuid(),
    label: '工时',
    render({ row }) {
      const { hour, minute } = getWorkerHours(
        row.startTime,
        row.endTime,
        row.overnightShift,
      )
      return `${hour}时 ${minute}分`
    },
  },
]

// #endregion
// ------------------动态变量------------------
// #region

// #endregion
// ------------------ref-----------
// #region
const dialogRef = ref<CustomDialogInstance | null>(null)
// #endregion
// ------------------reactive------
// #region
// #endregion
// ------------------computed------
// #region

// #endregion
// ------------------生命周期------------------
// #region

// #endregion
// ------------------内置方法---------------------
// #region
// #endregion
// ------------------方法---------------------
// #region
async function open() {
  dialogRef.value?.open?.()
  await nextTick()
  dialogRef.value?.setSaving?.(false)
}
function close() {
  dialogRef.value?.close?.()
}
// #endregion
defineExpose({
  open,
  close,
})
</script>

<template>
  <CustomDialog
    ref="dialogRef"
    title="班次查看"
    need-saving
    width="600px"
    :show-confirm-button="false"
  >
    <div class="height-vh-2/5 container">
      <view-table
        border
        :columns="columns"
        :show-toolbox="false"
        :data="unitShiftData"
        class="height-fill"
      />
    </div>
  </CustomDialog>
</template>

<style lang="scss" scoped>
//------------------组件样式------------------
//-------------样式穿透-------------
</style>
